package com.test.springbatch;

import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

/**
 * @author hadoop
 */
public class AppMain {

    /**
     * @param args
     */
    public static void main(String[] args) {
        ApplicationContext context;
        JobParametersBuilder jobPara = new JobParametersBuilder();  //设置文件路径参数  
        context = new FileSystemXmlApplicationContext(new String[]{"classpath:applicationContext-batch-myfirstbatch.xml"});
        String jobName = "ioSampleJob";
        Job job = (Job) context.getBean(jobName);
        JobLauncher launcher = (JobLauncher) context.getBean("jobLauncher");
        JobExecution result = null;
        try {
            result = launcher.run(job, jobPara.toJobParameters());
        } catch (Exception e) {
            e.printStackTrace();
        }
        ExitStatus es = result.getExitStatus();
        if (es.getExitCode().equals(ExitStatus.COMPLETED.getExitCode())) //任务正常完成
        {
            System.out.println("任务正常完成");
        } else {
            System.out.println("任务失败");
        }
    }

}  